pr<%@ Page language="vb" CodeFile="addVehicleStep5.aspx.vb" Inherits="addVehicleStep5_aspx_vb" %>

<%
    rowNumber = 0
    partnerID = Request.QueryString("partnerID")
    dealerID = Request.QueryString("dealerID")
    intClientID = Request.QueryString("clientID")
    driverID = Request.QueryString("driverID")
    If Len(partnerID) = 0 Or Len(dealerID) = 0 Or Len(intClientID) = 0 Or Len(driverID) = 0 Then
        Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
    Else
        partnerID = CLng(partnerID)
        dealerID = CLng(dealerID)
        intClientID = CLng(intClientID)
        driverID = CLng(driverID)
    End If
    dbOpen()
    RecSet = Conn.Execute("Select countryID From tblPartner Where partnerID = " & partnerID & "")
    If RecSet.EOF Then 
        Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
    Else
        countryID = RecSet.Fields("countryID").Value
    End IF
    RecSet.Close()
    RecSet = Nothing
    dbClose()
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        Over()
        strJS = ""
        strJS = strJS + "[""brandID"", ""<1""],"
        strJS = strJS + "[""modelID"", ""<1""],"
        If CDbl(countryID) = 3 Then 
            strJS = strJS + "[""vinNumber"", ""==''""],"
        Else
            strJS = strJS + "[""regnr"", ""==''""],"
        End IF
        strJS = strJS + "[""cylinderVolume"", ""<1""]"
        checkFields()
        dbOpen()
        RecSet = Conn.Execute("Select brandID, modelID, model From tblModel Order by model")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                brandID = RecSet.Fields("brandID").Value
                modelID = RecSet.Fields("modelID").Value
                model = RecSet.Fields("model").Value
                strSelectSubJS = strSelectSubJS + "new Array(" & modelID & "," & brandID & ",""" & model & """),"
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select brandID From tblBrand Order by brandID")
        Do Until RecSet.EOF
            brandID = RecSet.Fields("brandID").Value
            strSelectSubJS = strSelectSubJS + "new Array(0," & brandID & ","" ------------------------------------  ""),"
            RecSet.MoveNext()
        Loop
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        strSelectSubJS = Left(strSelectSubJS, Len(strSelectSubJS) - 1)
        strSelectSubHeadline = "Select car model"
        selectSub()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>VEHICLE INFORMATION - STEP 5 OF 7<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addVehicleStep5.aspx?do=save&partnerID=" & partnerID & "&dealerID=" & dealerID & "&clientID=" & intClientID & "&driverID=" & driverID & "' method='post' name='store_productsSearch' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Car make:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='brandID' id='brandID' onchange=""set_child_listbox(this, document.store_productsSearch.modelID,Product,'Products');"">")
        Response.Write("<option value=''> Select car make  ")
        dbOpen()
        RecSet = Conn.Execute("Select brandID, brand From tblBrand Order By brand")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                brandID = RecSet.Fields("brandID").Value
                brand = RecSet.Fields("brand").Value
                Response.Write("<option value='" & brandID & "'> " & brand & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_brandID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Car model:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='modelID' id='modelID' disabled>")
        Response.Write("<option value=''> Select car model ")
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_modelID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Licence number:</td><td align='right'><input type='text' name='regnr' id='regnr' size='40' maxlength='50'></td><td><div id='error_regnr' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>VIN-number:</td><td align='right'><input type='text' name='vinNumber' id='vinNumber' size='40' maxlength='50'></td><td><div id='error_vinNumber' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Contract number:</td><td align='right'><input type='text' name='contractNumber' id='contractNumber' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Cylinder volume:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='cylinderVolume' id='cylinderVolume'>")
        Response.Write("<option value=''> - select cylinder volume - ")
        Response.Write("<option value='1'>&nbsp; &nbsp; &nbsp; &nbsp;0 ")
        Response.Write("<option value='125'>&nbsp; &nbsp;125 ")
        Response.Write("<option value='500'>&nbsp; &nbsp;500 ")
        Response.Write("<option value='750'>&nbsp; &nbsp;750 ")
        For cylinderVolumeLoop = 10 To 99
            Response.Write("<option value='" & cylinderVolumeLoop & "00'> " & Left(cylinderVolumeLoop, 1) & " " & Mid(cylinderVolumeLoop, 2, 1) & "00 ")
        Next
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_cylinderVolume' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Step 6'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>SUBSCRIPTION PROCESS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select d.dealer, p.partnerName, c.country From ((tblDealer d INNER JOIN tblPartner p ON p.partnerID = d.partnerID) INNER JOIN tblCountry c ON c.countryID = p.countryID) Where d.dealerID = " & dealerID & "")
        If RecSet.EOF Then 
            Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
        Else
            dealer = RecSet.Fields("dealer").Value
            partnerName = RecSet.Fields("partnerName").Value
            country = RecSet.Fields("country").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select d.driver, c.client From (tblDriver d INNER JOIN tblClient c ON c.clientID = d.clientID) Where d.driverID = " & driverID & "")
        If RecSet.EOF Then 
            Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
        Else
            driver = RecSet.Fields("driver").Value
            client = RecSet.Fields("client").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr bgcolor='#eeeeee'><td>Country:</td><td>" & country & "</td></tr>")
        Response.Write("<tr><td>Partner:</td><td>" & partnerName & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Car dealer:</td><td>" & dealer & "</td></tr>")
        Response.Write("<tr><td>Client:</td><td>" & client & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Driver:</td><td>" & driver & "</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        brandID = Request.Form("brandID")
        modelID = Request.Form("modelID")
        regnr = Request.Form("regnr")
        vinNumber = Request.Form("vinNumber")
        contractNumber = Request.Form("contractNumber")
        cylinderVolume = Request.Form("cylinderVolume")
        brandID = CLng(brandID)
        modelID = CLng(modelID)
        cylinderVolume = CLng(cylinderVolume)
        If Len(regnr) > 0 Then 
            regnr = Trim(regnr)
            regnr = Replace(regnr, "'", "")
            regnr = Replace(regnr, """", "")
            regnr = Replace(regnr, "<", "")
            regnr = Replace(regnr, ">", "")
            regnr = Replace(regnr, "=", "")
            regnr = Replace(regnr, "&", "")
            regnr = UCase(regnr)
        Else
            regnr = "N/A"
        End IF
        If Len(vinNumber) > 0 Then 
            vinNumber = Trim(vinNumber)
            vinNumber = Replace(vinNumber, "'", "")
            vinNumber = Replace(vinNumber, """", "")
            vinNumber = Replace(vinNumber, "<", "")
            vinNumber = Replace(vinNumber, ">", "")
            vinNumber = Replace(vinNumber, "=", "")
            vinNumber = Replace(vinNumber, "&", "")
        Else
            vinNumber = "N/A"
        End IF
        If Len(contractNumber) > 0 Then 
            contractNumber = Trim(contractNumber)
            contractNumber = Replace(contractNumber, "'", "")
            contractNumber = Replace(contractNumber, """", "")
            contractNumber = Replace(contractNumber, "<", "")
            contractNumber = Replace(contractNumber, ">", "")
            contractNumber = Replace(contractNumber, "=", "")
            contractNumber = Replace(contractNumber, "&", "")
            contractNumber = UCase(contractNumber)
        Else
            contractNumber = "N/A"
        End IF
        If CInt(cylinderVolume) = 1 Then 
            cylinderVolume = 0
        End IF
        Response.Redirect("addVehicleStep6.aspx?partnerID=" & partnerID & "&dealerID=" & dealerID & "&clientID=" & intClientID & "&driverID=" & driverID & "&brandID=" & brandID & "&modelID=" & modelID & "&regnr=" & regnr & "&vinNumber=" & vinNumber & "&contractNumber=" & contractNumber & "&cylinderVolume=" & cylinderVolume & "")
    End IF
%>
